﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MTUnity.Utils
{

    public static class ToolUtils
    {
        public static List<T> GetCountFromList<T>(List<T> listDatasource , int iCount)
        {
            List<T> listResult = new List<T>();

            int iAlreadyAddCount = 0;
            for (int i = listDatasource.Count - 1; i >= 0; i--)
            {
                listResult.Add(listDatasource[i]);
                iAlreadyAddCount++;
                if (iAlreadyAddCount >= iCount)
                {
                    break;
                }
            }
            //listResult.Reverse();
            return listResult;
        }

        public static void LimitListMaxCount<T>(List<T> listDatasource , int iMaxCount)
        {
            if (listDatasource.Count < iMaxCount || listDatasource.Count == 0)
            {
                return;
            }
            while(listDatasource.Count > iMaxCount)
            {
                listDatasource.RemoveAt(0);
            }
        }

        public static bool LocationCheck(ELocationType eNeedCheck , ELocationType eFilter)
        {
            if ((eNeedCheck | eFilter) == eFilter)
            {
                return true;
            }
            return false;
        }
    }
}
